<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/28
 * Time: 17:53
 */

//进程使用场景
$curls =[
    'https://www.swoole.com/',
    'https://www.swoole.com/',
    'https://www.swoole.com/'
];
$wokPid=[];
for ($i=0 ; $i< count($curls);$i++){
//    开启子进程
    $pro = new swoole_process(function (swoole_process $process)use($i,$curls){
        $result = curls($curls[$i]);
        $process->write($result);//子进程获取到的数据写入到管道中
    },true);
    $pro->start();
    $wokPid[$pro->pid]= $pro;
}

foreach ($wokPid as $p){
    //获取写入的管道内容数据
    var_dump($p->read());
}



function curls($url){
    sleep(1);
    return '成功：'.$url.PHP_EOL;
}